package com.yonghui.springsecurityoauth2demo.service;

import com.yonghui.springsecurityoauth2demo.domain.OauthClientDetails;
import com.yonghui.springsecurityoauth2demo.mapper.OauthClientDetailsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author he_jiebing@jiuyv.com
 * @create 2024-05-13 16:13
 */

@Service
public class CustomClientDetailsService implements ClientDetailsService {
    
    @Autowired
    private OauthClientDetailsMapper oauthClientDetailsMapper;
    @Override
    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        OauthClientDetails clientDetails = oauthClientDetailsMapper.selectByPrimaryKey(clientId);

        if (clientDetails == null) {
            throw new ClientRegistrationException("Client not found: " + clientId);
        }


        return clientDetails;
    }
}
